package servlet;

 import common.Result; import dao.UserDao; import pojo.User; 
 import com.alibaba.fastjson.JSON;

 import javax.servlet.ServletException; import
 javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest; import
 javax.servlet.http.HttpServletResponse; import java.io.IOException; import
 java.util.List;
 
 @WebServlet("/users") 
 public class UserServlet extends HttpServlet {
 
 private UserDao userDao = new UserDao();
 
 @Override protected void doGet(HttpServletRequest request,
 HttpServletResponse response) throws ServletException, IOException {
 response.setContentType("application/json");
 response.setCharacterEncoding("UTF-8");
 
 List<User> result = userDao.FindAll();
 
 String jsonResponse = JSON.toJSONString(Result.success(result));
 response.getWriter().write(jsonResponse); } }
 
